<?php

$segment1 = $this->uri->segment(1);
$segment2 = $this->uri->segment(2);
$this->load->helper('menu');
$config = getMenu();

$admin = $this->session->userdata('adminDetail');

?>
<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">

    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">

        <!-- Sidebar user panel (optional) -->
        <!--
        <div class="user-panel">
            <div class="pull-left image">
                <img src="<?=$admin['avatar']?>" onerror="this.src='/assets/library/dist/img/user2-160x160.jpg'" class="img-circle">
            </div>
            <div class="pull-left info">
                <p><?=$admin['nickName']?></p>
                <a href="javascript:void(0);"><i class="fa fa-circle text-success"></i> <?=$admin['role']?></a>
            </div>
        </div>
        -->

        <!-- Sidebar Menu -->
        <ul class="sidebar-menu">
            <li class="header">HEADER</li>
            <!-- Optionally, you can add icons to the links -->
            <li <?=$segment1=='home' ? 'class="active"' : ''?>><a href="/home"><i class="fa fa-home"></i> <span>后台首页</span></a></li>

            <?php foreach($config as $key => $conf):?>
                <?php if(!empty($conf['subMenu'])): ?>
                    <li class="treeview <?=$key == $segment1 ? 'active' : ''?>">
                        <a href="javascript:void(0);">
                            <i class="fa <?=$conf['icon']?>"></i>
                            <span><?=$conf['name']?></span>
                            <span class="pull-right-container"><i class="fa fa-angle-left pull-right"></i></span>
                        </a>
                        <ul class="treeview-menu">
                            <?php foreach($conf['subMenu'] as $sub): ?>
                            <li <?=$sub['controller'] == $segment2 ? 'class="active"' : '';?>><a href="/<?=$key?>/<?=$sub['controller']?>/index"><i class="fa fa-circle-o"></i> <?=$sub['title']?></a></li>
                            <?php endforeach; ?>
                        </ul>
                    </li>
                <?php else: ?>
                    <li <?=$key == $segment1 ? 'class="active"' : '';?> ><a href="<?=$conf['url']?>"><i class="fa <?=$conf['icon']?>"></i> <span><?=$conf['name']?></span></a></li>
                <?php endif; ?>
            <?php endforeach;?>
        </ul>
        <!-- /.sidebar-menu -->
    </section>
    <!-- /.sidebar -->
</aside>